package client.comm.baoding.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.comm.commlib.network.data.JsonResult
import client.comm.baoding.api.bean.IntegralRet
import client.comm.baoding.ui.viewmodel.MiddleVm
import client.comm.commlib.network.data.Ret


class JifenViewModel(app: Application) : MiddleVm(app) {
    val isShowing = MutableLiveData<Boolean>(false)

    val isOneLoading = MutableLiveData<Boolean>(false)
    val isTwoLoading = MutableLiveData<Boolean>(false)
//    val isThreeLoading = MutableLiveData<Boolean>(false)
//    val isFourLoading = MutableLiveData<Boolean>(false)
    val pageOne = MutableLiveData<Int>(0)
    val pageTwo = MutableLiveData<Int>(0)
//    val pageThree = MutableLiveData<Int>(0)
//    val pageFour = MutableLiveData<Int>(0)
    val callOne = MutableLiveData<JsonResult<IntegralRet>>()
    val callTwo = MutableLiveData<JsonResult<IntegralRet>>()

    val integralConvertCall = MutableLiveData<JsonResult<Ret>>()


//    val callThree = MutableLiveData<JsonResult<IntegralRet>>()
//    val callFour = MutableLiveData<JsonResult<IntegralRet>>()

    fun holdOne() {
        if (isOneLoading.value!!)
            return
        hold({
            server.user_integral_record(pageOne.value!!, -1)
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            callOne.value = it
        }, complete = {
            isOneLoading.value = false
        })
    }

    fun holdTwo() {
        if (isTwoLoading.value!!)
            return
        hold({
            server.user_integral_record(pageTwo.value!!, 0)
        }, {
            isTwoLoading.value = true
            pageTwo.value = pageTwo.value!! + 1
        }, {
            callTwo.value = it
        }, complete = {
            isTwoLoading.value = false
        })
    }



    //积分转换
    fun integralConvertCall(id: String) {
        isShowing.value = true
        hold({
            server.confirm_integral_transfer(id)
        }, success = {
            integralConvertCall.value = it
        }, complete = {
            isShowing.value = false
        })
    }


    /*fun holdThree() {
        if (isThreeLoading.value!!)
            return
        hold({
            server.user_coin_record(pageThree.value!!, 1)
        }, {
            isThreeLoading.value = true
            pageThree.value = pageThree.value!! + 1
        }, {
            callThree.value = it
        }, complete = {
            isThreeLoading.value = false
        })
    }

    fun holdFour() {
        if (isFourLoading.value!!)
            return
        hold({
            server.user_coin_record(pageFour.value!!, 2)
        }, {
            isFourLoading.value = true
            pageFour.value = pageFour.value!! + 1
        }, {
            callFour.value = it
        }, complete = {
            isFourLoading.value = false
        })
    }*/





}